package com.ktgj.customer.controller;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.customer.domain.Employee;
import com.ktgj.customer.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.EmployeeThing;
import com.ktgj.customer.service.IEmployeeThingService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 待跟进事项Controller
 * 
 * @author ruoyi
 * @date 2022-09-23
 */
@RestController
@RequestMapping("/thing")
public class EmployeeThingController extends BaseController
{
    @Autowired
    private IEmployeeThingService employeeThingService;
    @Autowired
    private ILoginService loginService;

    /**
     * 查询待跟进事项列表
     */
//    @PreAuthorize(hasPermi = "customer:thing:list")
    @PostMapping("/list")
    public TableDataInfo list(HttpServletRequest request, @RequestBody EmployeeThing employeeThing) throws Exception
    {
        String token = request.getHeader("token");
        Employee employee = loginService.getLoginEmployeeByToken(token);
        if (employee == null)
        {
            throw new Exception("登录已过期");
        }
//        startPage();
        List<EmployeeThing> list = employeeThingService.selectEmployeeThingList(employee, employeeThing);
        return getDataTable(list);
    }

    /**
     * 导出待跟进事项列表
     */
    @PreAuthorize(hasPermi = "customer:thing:export")
    @Log(title = "待跟进事项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmployeeThing employeeThing) throws IOException
    {
        List<EmployeeThing> list = new ArrayList<>();
//        List<EmployeeThing> list = employeeThingService.selectEmployeeThingList(employeeThing);
        ExcelUtil<EmployeeThing> util = new ExcelUtil<EmployeeThing>(EmployeeThing.class);
        util.exportExcel(response, list, "待跟进事项数据");
    }

    /**
     * 获取待跟进事项详细信息
     */
    @PreAuthorize(hasPermi = "customer:thing:query")
    @GetMapping(value = "/{employeeThingId}")
    public AjaxResult getInfo(@PathVariable("employeeThingId") Long employeeThingId)
    {
        return AjaxResult.success(employeeThingService.selectEmployeeThingById(employeeThingId));
    }

    /**
     * 新增待跟进事项
     */
    @PreAuthorize(hasPermi = "customer:thing:add")
    @Log(title = "待跟进事项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmployeeThing employeeThing)
    {
        return toAjax(employeeThingService.insertEmployeeThing(employeeThing));
    }

    /**
     * 修改待跟进事项
     */
//    @PreAuthorize(hasPermi = "customer:thing:edit")
//    @Log(title = "待跟进事项", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody EmployeeThing employeeThing)
    {
        return toAjax(employeeThingService.updateEmployeeThing(employeeThing));
    }

    /**
     * 删除待跟进事项
     */
    @PreAuthorize(hasPermi = "customer:thing:remove")
    @Log(title = "待跟进事项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{employeeThingIds}")
    public AjaxResult remove(@PathVariable Long[] employeeThingIds)
    {
        return toAjax(employeeThingService.deleteEmployeeThingByIds(employeeThingIds));
    }
}
